$(function () {
    var claimBill_datagrid = $("#claimBill_datagrid");
    var claimBill_dialog = $("#claimBill_dialog");
    var claimBill_dialoginfo=  $("#claimBill_dialoginfo");
    claimBill_datagrid.datagrid({
        url:"/accident/list?status=7",
        fit:true,
        columns:[[
            {field:'x',checkbox:true},
            {field:'id',title:'id',width:10,hidden:true}, //hidden 隐藏显示该列
            {field:'status',title:'当前状态',width:100 , formatter: function(value,row,index){
                    if (value ==1){
                        return "<font style='color: red'>保单失效</font>";
                    } else if(value==2) {
                        return "<font style='color: blue '>待验证</font>";
                    } else if(value==3) {
                        return "<font style='color: #681818 '>验证完,待填理赔</font>";
                    }else if(value==4) {
                        return "<font style='color: blueviolet '>废弃</font>";
                    }else if(value==5) {
                        return "<font style='color: #3baae3 '>待审核</font>";
                    }else if(value==6) {
                        return "<font style='color: red '>被拒审核</font>";
                    }else if(value==7) {
                        return "<font style='color: #26b3f7 '>审核完,待付款给保人</font>";
                    }else if(value==8) {
                        return "<font style='color: #00ee00 '>已赔付</font>";
                    }
                }},
            {field:'lat_name',title:'报案人姓名',width:50},
            {field:'pay_number',title:'保险单号',width:50},
            {field:'lat_tel',title:'联系方式',width:50},
            {field:'otime',title:'报案时间',width:50},
            {field:'duty',title:'事故责任',width:50},
            {field:'ename',title:'验证员工',width:50},
            {field:'info',title:'备注',width:50}
        ]],
        rownumbers:true,
        striped:true,
        singleSelect:true,
        toolbar:"#claimBill_toolbar",
        pagination:true,
        fitColumns:true,

    });
    //弄出一个用于查看案件详情的对话框
    claimBill_dialog.dialog({
        width:400,
        height:400,
        buttons:"#gb",
        closed:"true"
    });


    //弄出一个用于查看赔损明细的对话框
    claimBill_dialoginfo.dialog({
        width:400,
        height:400,
        buttons:"#gc",
        closed:"true"
    });
    
    var cmdObj = {
        //刷新列表数据
        reload: function () {
            claimBill_datagrid.datagrid("reload");
        },
        //关闭查看案件详情的对话框
        shut:function() {
            claimBill_dialog.dialog("close");
        },
        //关闭查看赔损明细的对话框
        shutc:function() {
            claimBill_dialoginfo.dialog("close");
        },




        //审核完,待付款给保人修改状态值为已赔付
        discard:function(){
            var row= claimBill_datagrid.datagrid("getSelected");
            console.log(row);
            if(row==null){
                $.messager.alert("温馨提示","请选择要编辑的数据");
                return;
            }

            $.messager.confirm('温馨提示',"请再次确认你的操作",function (r) {
                if(r){
                    //1:发起请求修改状态
                    $.get("/accident/changeStatus",{id:row.id,status:8},function (data) {
                        if(data.succeed){
                            //2:刷新列表数据

                            claimBill_datagrid.datagrid("load");
                            //将数据提交到汇总表中保存操作
                            $.get("/compersationInfo/saveclaimcount",{id:row.id});
                        }else{
                            $.messager.alert("温馨提示",data.errorMsg);
                        }
                    });


                }
            });
        },
        //查看案件详情
        chackCase:function(){

            //从datagrid中获取选中的那一行数据
            var row=claimBill_datagrid.datagrid("getSelected");
            if(row==null){
                $.messager.alert("温馨提示","请选择要编辑的行");
            }else{
                //打开查看案件详情编辑对话框
                claimBill_dialog.dialog("setTitle","查看案件详情");
                claimBill_dialog.dialog("open");
                $("#claimBill_form").form("load",row);//数据回显
            }
        },
        //查看赔损明细
        checkInfo:function(){

            //从datagrid中获取选中的那一行数据
            var row=claimBill_datagrid.datagrid("getSelected");

            row['payNumber']=row.pay_number;
            console.log(row);
            if(row==null){
                $.messager.alert("温馨提示","请选择要编辑的行");
            }else{
                $.get("/checkClaim/selectByaccidentId",{accidentId:row.id},function (data){

                    //打开修改赔损明细编辑对话框
                    claimBill_dialoginfo.dialog("setTitle","查看赔损明细");
                    claimBill_dialoginfo.dialog("open");

                    $("#claimBill_forminfo").form("load",data); //数据回显

                    //给保单编号设置值
                    console.log(row.payNumber);
                    $("#payNumber").textbox("setValue",row.payNumber);

                })
            }
        }
    }
    //调用
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    })
})











